package com.huiquan.management.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.huiquan.framework.utils.RequestParamUtil;
import com.huiquan.management.service.OnlineTimeStatisticService;

@Controller
public class OnlineTimeStatisticController {

	@Autowired
	private OnlineTimeStatisticService onlineTimeStatisticService;

	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/management/online_time_statistic_list.htm")
	public ModelAndView onlineTimeStatisticList(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		String tabid = req.getParameter("tabid");
		// 维护页面参数到session
		Map<String, Object> pageParam;
		if (tabid != null && !tabid.isEmpty()) {
			pageParam = new HashMap<>();
			pageParam.put("tabid", tabid);
			pageParam.put("start", "1");
			pageParam.put("exactSearchFlag", "0");

			req.getSession().setAttribute("pageParam", pageParam);
		} else {
			pageParam = (Map<String, Object>) req.getSession().getAttribute("pageParam");
		}
		String type = RequestParamUtil.getParamByRequestOrSession(req, pageParam, "type");

		return onlineTimeStatisticService.onlineTimeStatisticList(type);
	}

	@RequestMapping(value = "/management/online_time_statistic_export.htm")
	public void export(HttpServletRequest req, HttpServletResponse resp) throws Exception {

		onlineTimeStatisticService.export(resp);

	}
}
